﻿using System.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Earworm.Web.DBM;

namespace Earworm.Web.Registration
{
    public partial class RegisterUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string me = "";

            CustomValidator val = new CustomValidator();
            EarwormDataContext ear = new EarwormDataContext();
            var i = ear.sp_create_new_user(txtFirst.Text, txtLast.Text, txtEmail.Text, txtPass.Text, false, txtUsername.Text, ref me);


            if (i.ReturnValue.ToString() == "0")
            {
                val.IsValid = false;
                val.ErrorMessage = me;
                txtConfirmPass.Text = "";
                txtPass.Text = "";
                this.Page.Validators.Add(val);
            }
            else
            {
                txtUsername.Text = "";
                txtPass.Text = "";
                txtLast.Text = "";
                txtFirst.Text = "";
                txtEmail.Text = "";
                txtConfirmPass.Text = "";
                Response.Redirect("~/Registration/Login.aspx");
            }
        }
    }


}